package reflectx

import "reflect"

func CopyNonZeroFields(dst, src interface{}) {
	dv := reflect.ValueOf(dst).Elem()
	sv := reflect.ValueOf(src).Elem()

	for i := 0; i < sv.NumField(); i++ {
		sf := sv.Field(i)
		df := dv.Field(i)

		zero := reflect.Zero(sf.Type()).Interface()
		if !reflect.DeepEqual(sf.Interface(), zero) {
			if df.CanSet() {
				df.Set(sf)
			}
		}
	}
}
